package com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.dto.Table09421Dto;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.dto.SaveTable09421FormDataDto;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.vo.Table09421FormDataVo;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.vo.Table09421ListVo;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.dto.Table09421ListDto;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.vo.Table18109Vo;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.entity.Table18109;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.dto.Table18109Dto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.entity.Table09421;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.vo.Table09421Vo;
import com.xjrsoft.module.customerTwo.companyManage.calculationComponentExample.service.ITable09421Service;

/**
 *  控制器
 *
 * @author pp
 * @since 2022-08-25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/calculationcomponentexample")
@Api(value = "CalculationComponentExample", tags = "CalculationComponentExample接口")
public class Table09421Controller {


	private final ITable09421Service table09421Service;


	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入table09421")
	@SaCheckPermission("calculationcomponentexample:view")
	public Response<Table09421FormDataVo> getFormData(@PathVariable String id) {
		Table09421FormDataVo formDataVo = new Table09421FormDataVo();
		// 主表数据
		Table09421 table09421 = table09421Service.getById(id);
		formDataVo.setTable09421Vo(BeanUtil.copy(table09421, Table09421Vo.class));
		// 从表数据
		formDataVo.setTable18109VoList(BeanUtil.copyList(table09421Service.getTable18109ByParentId(id), Table18109Vo.class));
		return Response.ok(formDataVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入table09421")
	@SaCheckPermission("calculationcomponentexample:view")
	public Response<PageOutput<Table09421ListVo>> getPageList(Table09421ListDto listDto) {
		IPage<Table09421> page = table09421Service.getPageList(listDto);
		List<Table09421ListVo> records = BeanUtil.copyList(page.getRecords(), Table09421ListVo.class);
		// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入table09421")
	@SaCheckPermission("calculationcomponentexample:add")
	public Response save(@RequestBody SaveTable09421FormDataDto formDto) {
		Table09421Dto table09421Dto = formDto.getTable09421Dto();
		Table09421 table09421 = BeanUtil.copy(table09421Dto, Table09421.class);
		List<Table18109Dto> table18109DtoList = formDto.getTable18109Dto();
		List<Table18109> table18109List = BeanUtil.copyList(table18109DtoList, Table18109.class);
		String dataId = table09421Service.addTable09421(table09421, table18109List);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入table09421")
	@SaCheckPermission("calculationcomponentexample:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTable09421FormDataDto formDto) {
		Table09421Dto table09421Dto = formDto.getTable09421Dto();
		Table09421 table09421 = BeanUtil.copy(table09421Dto, Table09421.class);

		List<Table18109Dto> table18109DtoList = formDto.getTable18109Dto();
		List<Table18109> table18109List = BeanUtil.copyList(table18109DtoList, Table18109.class);
		return Response.status(table09421Service.updateTable09421(id, table09421, table18109List));
	}


	
	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission("calculationcomponentexample:batchDelete")
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(table09421Service.delete(ids));
	}

	
}
